﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using NLBS.Entity;

namespace NLBS.Data
{
    public partial class SqlDataProvider : DbProvider
    {
        #region settings

        public override Dictionary<string, Setting> GetSettings()
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("SELECT set_name, set_type, set_value0, set_value1 FROM dbo.blog_Settings");

            IDataReader dr = db.ExecuteReader(dbCommand);
            Setting setting = null;
            Dictionary<string, Setting> list = new Dictionary<string, Setting>();
            while (dr.Read())
            {
                setting = CommonDataProvider.PopulateSettingFromIDataReader(dr);
                list.Add(setting.Name, setting);
            }
            return list;
        }

        public override void UpdateSettings(Setting set)
        {
            
            DbCommand dbCommand = db.GetSqlStringCommand("UPDATE [dbo].[blog_Settings] SET [set_type] = @type, [set_value0] = @value0, [set_value1] = @value1 WHERE (([set_name] = @name))");
            db.AddInParameter(dbCommand, "name", DbType.String, set.Name);
            db.AddInParameter(dbCommand, "type", DbType.Int16, set.Type);
            db.AddInParameter(dbCommand, "value0", DbType.Int32, set.Value0);
            db.AddInParameter(dbCommand, "value1", DbType.String, set.Value1);
            db.ExecuteNonQuery(dbCommand);
        }

        #endregion
    }
}
